package com.ldgk.pim.client.event;

import com.google.gwt.event.shared.GwtEvent;
import com.ldgk.pim.data.Place;

/**
 * Event used to notify about request creation, updated and deletion 
 * of distribution places
 *
 */
public class PlaceEvent extends GwtEvent<PlaceEventHandler>{
	/** Event type */
	public enum Type{ADD,EDIT,DELETE};
	
	private static final GwtEvent.Type<PlaceEventHandler> TYPE = new GwtEvent.Type<PlaceEventHandler>();

	private Place place;
	private Type type;
	
	public PlaceEvent(Place place, Type type){
		this.place = place;
		this.type = type;
	}
	
	@Override
	protected void dispatch(PlaceEventHandler handler) {
		if(this.type == Type.ADD ){
			handler.addPlace(this.place);
		}else if(this.type == Type.EDIT ){
			handler.editPlace(this.place);
		}else if(this.type == Type.DELETE ){
			handler.deletePlace(this.place);
		}
	}

	@Override
	public com.google.gwt.event.shared.GwtEvent.Type<PlaceEventHandler> getAssociatedType() {
		return TYPE;
	}

	public static GwtEvent.Type<PlaceEventHandler> getType(){
		return TYPE;
	}
}